home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Libraries / tcl7.4b3 / doc / proc.n < prev    next >
Encoding:
Text File  |  1994-12-17  |  2.8 KB  |  68 lines

  1. '\"
  2. '\" Copyright (c) 1993 The Regents of the University of California.
  3. '\" Copyright (c) 1994 Sun Microsystems, Inc.
  4. '\"
  5. '\" See the file "license.terms" for information on usage and redistribution
  6. '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  7. '\" 
  8. '\" @(#) proc.n 1.2 94/12/17 16:18:37
  9. '\" 
  10. .so man.macros
  11. .HS proc tcl
  12. .BS
  13. '\" Note:  do not modify the .SH NAME line immediately below!
  14. .SH NAME
  15. proc \- Create a Tcl procedure
  16. .SH SYNOPSIS
  17. \fBproc \fIname args body\fR
  18. .BE
  19.  
  20. .SH DESCRIPTION
  21. .PP
  22. The \fBproc\fR command creates a new Tcl procedure named
  23. \fIname\fR, replacing
  24. any existing command or procedure there may have been by that name.
  25. Whenever the new command is invoked, the contents of \fIbody\fR will
  26. be executed by the Tcl interpreter.
  27. \fIArgs\fR specifies the formal arguments to the
  28. procedure.  It consists of a list, possibly empty, each of whose
  29. elements specifies
  30. one argument.  Each argument specifier is also a list with either
  31. one or two fields.  If there is only a single field in the specifier
  32. then it is the name of the argument; if there are two fields, then
  33. the first is the argument name and the second is its default value.
  34. .PP
  35. When \fIname\fR is invoked a local variable
  36. will be created for each of the formal arguments to the procedure; its
  37. value will be the value of corresponding argument in the invoking command
  38. or the argument's default value.
  39. Arguments with default values need not be
  40. specified in a procedure invocation.  However, there must be enough
  41. actual arguments for all the
  42. formal arguments that don't have defaults, and there must not be any extra
  43. actual arguments.  There is one special case to permit procedures with
  44. variable numbers of arguments.  If the last formal argument has the name
  45. \fBargs\fR, then a call to the procedure may contain more actual arguments
  46. than the procedure has formals.  In this case, all of the actual arguments
  47. starting at the one that would be assigned to \fBargs\fR are combined into
  48. a list (as if the \fBlist\fR command had been used); this combined value
  49. is assigned to the local variable \fBargs\fR.
  50. .PP
  51. When \fIbody\fR is being executed, variable names normally refer to
  52. local variables, which are created automatically when referenced and
  53. deleted when the procedure returns.  One local variable is automatically
  54. created for each of the procedure's arguments.
  55. Global variables can only be accessed by invoking
  56. the \fBglobal\fR command or the \fBupvar\fR command.
  57. .PP
  58. The \fBproc\fR command returns an empty string.  When a procedure is
  59. invoked, the procedure's return value is the value specified in a
  60. \fBreturn\fR command.  If the procedure doesn't execute an explicit
  61. \fBreturn\fR, then its return value is the value of the last command
  62. executed in the procedure's body.
  63. If an error occurs while executing the procedure
  64. body, then the procedure-as-a-whole will return that same error.
  65.  
  66. .SH KEYWORDS
  67. argument, procedure
  68.